<template>
	<view class="flow-container" :style="{ height: `${windowHeight}px` }">
		<!--  -->
		<view class="flow-measure" v-if="flowNum === 1">
			<view class="title"> 内容填写1 </view>
			<view class="table">
				<uni-table ref="table" emptyText="暂无更多数据" class="click-table">
					<uni-tr>
						<uni-th width="40" align="center">序号</uni-th>
						<uni-th width="160" align="center">主要风险点及安全措施</uni-th>
						<uni-th width="60" align="center">是否涉及</uni-th>
						<uni-th width="60" align="center">是否安全</uni-th>
						<uni-th width="60" align="center">确认人</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in tableData" :key="index">
						<uni-td align="center">{{ index + 1 }}</uni-td>
						<uni-td align="center">
							<rich-text :nodes="item.measure" @click="addNum(item.measure, index)">
							</rich-text>
						</uni-td>
						<uni-td align="center">
							<switch color="#19be6b" :checked="item.involve" />
						</uni-td>
						<uni-td align="center">
							<switch color="#19be6b" :checked="item.safety" />
						</uni-td>
						<uni-td align="center">
							{{ item.submitPerson }}
						</uni-td>
					</uni-tr>
				</uni-table>
			</view>
			<view class="title"> 动火负责人签字 </view>
			<view class="charge-people">
				<checkbox-group>
					<checkbox value="cb" checked="true" class="check-box" />
					我已明白本作业许可证规定内容，并告知每一个相关人员，共同遵守执行；相关动火安全措施已全部落实，符合动火要求。
				</checkbox-group>
				<view class="sign"> 请在这个区域进行签字 </view>
				<view class="time">月 日 时 分</view>
			</view>
			<view class="title"> 指定签字人 </view>
			<uni-forms ref="valiForm" :rules="rules" :modelValue="valiFormData" border>
				<uni-forms-item label="安全交底人：" required name="chargePeople">
					<uni-data-select :localdata="peopleOption" v-model="valiFormData.chargePeople" />
				</uni-forms-item>
				<uni-forms-item label="接受交底人：" required name="tutelagePeople">
					<uni-data-select :localdata="peopleOption" v-model="valiFormData.tutelagePeople" />
				</uni-forms-item>
				<uni-forms-item label="动火监护人：" required name="operationPeople">
					<uni-data-select :localdata="peopleOption" v-model="valiFormData.operationPeople" />
				</uni-forms-item>
			</uni-forms>

			<button class="submit-btn">确认</button>
		</view>
		<!-- 措施填写 -->
		<view class="flow-measure" v-if="flowNum === 2">
			<view class="title"> 安全措施填写 </view>
			<view class="table">
				<uni-table ref="table" emptyText="暂无更多数据" class="click-table">
					<uni-tr>
						<uni-th width="40" align="center">序号</uni-th>
						<uni-th width="160" align="center">主要风险点及安全措施</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in confirmItem" :key="index">
						<uni-td align="center">{{ index + 1 }}</uni-td>
						<uni-td align="center">
							<rich-text :nodes="item.measure" @click="addNum(item.measure, index)">
							</rich-text>

						</uni-td>

					</uni-tr>
				</uni-table>
			</view>
			<view class="title"> 编制人签字 </view>
			<view class="charge-people">

				<uni-data-checkbox multiple v-model="checkbox1" :localdata="noticeCheck"></uni-data-checkbox>
				<view class="sign" v-if="measureFill.url == ''" @click="handleSign(2)"> 请在这个区域进行签字 </view>
				<view v-if="measureFill.url">
					<image :src="measureFill.url"></image>
				</view>
				<!-- <view class="time">月 日 时 分</view> -->
			</view>


			<button class="submit-btn" @click="onSubmit(2)">确认</button>
		</view>
		<!-- 措施确认 -->
		<view class="flow-measure" v-if="flowNum === 3">
			<view class="title"> 安全措施确认 </view>
			<view class="table">
				<uni-table ref="table" emptyText="暂无更多数据" class="click-table">
					<uni-tr>
						<uni-th width="40" align="center">序号</uni-th>
						<uni-th width="160" align="center">主要风险点及安全措施</uni-th>
						<uni-th width="60" align="center">是否涉及</uni-th>
						<uni-th width="60" align="center">是否安全</uni-th>
						<uni-th width="60" align="center">确认人</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in confirmItem" :key="index">
						<uni-td align="center">{{ index + 1 }}</uni-td>
						<uni-td align="center">
							<rich-text :nodes="item.measure" @click="addNum(item.measure, index)">
							</rich-text>

						</uni-td>
						<uni-td align="center">
							<switch color="#19be6b" :checked="item.isInvolve" />
						</uni-td>
						<uni-td align="center">
							<switch color="#19be6b" :checked="item.isSafe" />
						</uni-td>
						<uni-td align="center">
							{{ item.submitPerson }}
						</uni-td>
					</uni-tr>
				</uni-table>
			</view>
			<view class="title"> {{cobfirmSignTitle}} </view>
			<view class="charge-people">

				<uni-data-checkbox multiple v-model="checkbox1" :localdata="noticeCheck"></uni-data-checkbox>
				<view class="sign" v-if="measureConfirm.url == ''" @click="handleSign(3)"> 请在这个区域进行签字 </view>
				<view v-if="measureConfirm.url">
					<image :src="measureConfirm.url"></image>
				</view>
				<!-- <view class="time">月 日 时 分</view> -->
			</view>


			<button class="submit-btn" @click="onSubmit(3)">确认</button>
		</view>
		<!-- 现场确认 -->
		<view class="flow-measure" v-if="flowNum === 4">
			<template v-if="detailObj.yesStatus == 0">
				<view class="title"> 安全交底人签字 </view>
				<view class="charge-people">

					<uni-data-checkbox multiple v-model="checkbox1" :localdata="noticeCheck"></uni-data-checkbox>
					<view class="sign" @click="handleSign(4)" v-if="siteConfirm.url == ''"> 请在这个区域进行签字 </view>
					<view v-if="siteConfirm.url">
						<image :src="siteConfirm.url"></image>
					</view>

				</view>
				<view class="img-upload">
					<view class="title">上传图片：</view>
					<uni-file-picker v-model="imageValue" fileMediatype="image" mode="grid" @select="handleFile"
						@progress="progress" @success="success" @fail="fail" @delete="deleteFile" />
				</view>
			</template>
			<template v-if="detailObj.yesStatus == 1">

				<view class="title"> 接受交底人签字 </view>
				<view class="charge-people">

					<uni-data-checkbox multiple v-model="checkbox1" :localdata="noticeCheck"></uni-data-checkbox>
					<view class="sign" @click="handleSign(4)" v-if="siteConfirm.url == ''"> 请在这个区域进行签字 </view>
					<view v-if="siteConfirm.url">
						<image :src="siteConfirm.url"></image>
					</view>
				</view>
			</template>
			<template v-if="specialJobType == '动火作业票' && detailObj.yesStatus == 2 ">

				<view class="title"> 动火监护人签字 </view>
				<view class="charge-people">

					<uni-data-checkbox multiple v-model="checkbox1" :localdata="noticeCheck"></uni-data-checkbox>
					<view class="sign" @click="handleSign(4)" v-if="siteConfirm.url == ''"> 请在这个区域进行签字 </view>
					<view v-if="siteConfirm.url">
						<image :src="siteConfirm.url"></image>
					</view>
				</view>
			</template>

			<button class="submit-btn" @click="onSubmit(4)">确认</button>
		</view>
		<!-- 审核 -->
		<view class="flow-measure" v-if="flowNum === 5">
			<!-- 审核签字人审核状态 -->
			<template v-if="detailObj.shStatus == 0">
				<view class="title"> {{examineProcessTitle[0]}} </view>
				<view class="charge-people">
					<uni-data-checkbox v-model="examineObj.approvalStatus" :localdata="approveArr" />
					<view class="sign" @click="handleSign(examineProcessTitle[0])"
						v-if="examineObj.approvalStatus == 1 && examineObj.url == ''">
						请在这个区域进行签字 </view>
					<view v-if="examineObj.url" class="view-img">
						<image :src="examineObj.url"></image>
					</view>
					<uni-easyinput type="textarea" autoHeight v-model="examineObj.approvalRemark"
						placeholder="请输入审批意见"></uni-easyinput>
				</view>
			</template>
			<template v-else-if="detailObj.shStatus == 1 || detailObj.specialGrade <= 2">

				<view class="title"> {{examineProcessTitle[1]}} </view>
				<view class="charge-people">
					<uni-data-checkbox v-model="examineObj.approvalStatus" :localdata="approveArr" />
					<view class="sign" v-if="examineObj.approvalStatus == 1 && examineObj.url == ''"
						@click="handleSign(examineProcessTitle[1])"> 请在这个区域进行签字
					</view>
					<view v-if="examineObj.url != '' && examineObj.approvalStatus == 1" class="view-img">
						<image :src="examineObj.url"></image>
					</view>
					<!-- <view class="time">月 日 时 分</view> -->
				</view>
				<view style="margin-top: 8rpx;">
					<uni-easyinput type="textarea" autoHeight v-model="examineObj.approvalRemark"
						placeholder="请输入审批意见"></uni-easyinput>
				</view>
			</template>


			<template v-else-if="detailObj.shStatus == 2">
				<view class="title"> {{examineProcessTitle[2]}} </view>
				<view class="charge-people">
					<uni-data-checkbox v-model="examineObj.approvalStatus" :localdata="approveArr" />
					<view class="sign" v-if="examineObj.approvalStatus == 1 && examineObj.url == ''"
						@click="handleSign(examineProcessTitle[2])"> 请在这个区域进行签字 </view>
					<view v-if="examineObj.url != ''" class="view-img">
						<image :src="examineObj.url"></image>
					</view>
					<!-- 	<view v-if="examineObj.url">
						<image :src="examineObj.url"></image>
					</view> -->
					<!-- <view class="time">月 日 时 分</view> -->
				</view>
				<view style="margin-top: 8rpx;">
					<uni-easyinput type="textarea" autoHeight v-model="examineObj.approvalRemark"
						placeholder="请输入审批意见"></uni-easyinput>
				</view>
			</template>

			<template v-else-if="detailObj.shStatus == 3 || examineProcessTitle[3] !== ''">

				<view class="title"> {{examineProcessTitle[3]}} </view>
				<view class="charge-people">
					<uni-data-checkbox v-model="approve" :localdata="approveArr" />
					<view class="sign" v-if="approve == 1 && examineObj.url == ''"
						@click="handleSign(examineProcessTitle[3])"> 请在这个区域进行签字 </view>
					<view v-if="examineObj.url != ''" class="view-img">
						<image :src="examineObj.url"></image>
					</view>

					<!-- <view class="time">月 日 时 分</view> -->
				</view>
				<view style="margin-top: 8rpx;">
					<uni-easyinput type="textarea" autoHeight v-model="examineObj.approvalRemark"
						placeholder="请输入审批意见"></uni-easyinput>
				</view>
			</template>


			<button class="submit-btn" @click="onSubmit(5)">确认</button>
		</view>

		<!-- 作业分析 -->
		<view class="flow-measure" v-if="flowNum === 6">
			<template v-if="topProcessTitle[5] == '作业分析' && specialJobType == '动火作业票'">


				<uni-forms ref="anaValiForm" :rules="anaRules" :modelValue="anaValiFormData" border>
					<view v-for="(item, index) in anaValiFormData.dynamicItem" :key="index">
						<view class="top-title">
							<view class="title"> 作业分析 {{index + 1}}</view>
							<uni-icons type="trash" size="30" v-if="index !== 0"
								@click="deleteItem(item, index)"></uni-icons>
						</view>

						<uni-forms-item label="动火分析时间：" required name="fxTime">
							<uni-datetime-picker :border="false" type="date" :disabled="workStatus"
								v-model="item.fxTime" />
						</uni-forms-item>
						<uni-forms-item label="分析点名称：" required name="fxName">
							<uni-easyinput v-model="item.fxName" :disabled="workStatus" placeholder="请输入"
								:inputBorder="false" />
						</uni-forms-item>
						<uni-forms-item label="分析数据(%)：" required name="fxData">
							<uni-easyinput v-model="item.fxData" type="number" :disabled="workStatus" placeholder="请输入"
								:inputBorder="false" />
						</uni-forms-item>
						<uni-forms-item label="分析数据(LEL)：" required name="fxDataTwo">
							<uni-easyinput v-model="item.fxDataTwo" type="number" :disabled="workStatus"
								placeholder="请输入" :inputBorder="false" />
						</uni-forms-item>
						<uni-forms-item label="分析人：" required name="regionSign">
							<uni-data-select :localdata="allUsers" :disabled="workStatus" :arrayConfig="configParams"
								v-model="item.regionSign" />
						</uni-forms-item>
						<uni-forms-item label="计划动火时间：" required name="startEndTime">
							<uni-datetime-picker :border="false" :disabled="workStatus" type="datetimerange"
								v-model="item.startEndTime" />
						</uni-forms-item>
					</view>

					<view class="btns">
						<button class="submit-btn" @click="finishBtn">结束作业</button>
						<button class="submit-btn" @click="addItem">新增作业分析</button>
					</view>
					<template v-if="workStatus">
						<view class="title"> 指定签字人 </view>
						<uni-forms-item label="结束作业负责人：" required name="overApprover">

							<uni-data-select v-model="anaValiFormData.overApprover" :arrayConfig="configParams"
								:localdata="allUsers"></uni-data-select>
						</uni-forms-item>
					</template>

				</uni-forms>
				<!-- <uni-forms ref="anaValiForm" :rules="anaRules" :modelValue="anaValiFormData" border>
					<uni-forms-item label="结束作业负责人：" required name="overApprover">

						<uni-data-select v-model="valiFormData.overApprover" :arrayConfig="configParams"
							:localdata="allUsers"></uni-data-select>
					</uni-forms-item>
				</uni-forms> -->

			</template>
			<tempalte v-if="topProcessTitle[5] == '作业分析' && specialJobType == '受限空间安全作业票'">
				<view class="title"> 作业分析 </view>
				<uni-forms ref="anaValiForm" :rules="anaRules" :modelValue="anaValiFormData" border>
					<uni-forms-item label="氧气含量：" required name="oxygenContent">
						<uni-datetime-picker :border="false" type="date" v-model="anaValiFormData.oxygenContent" />
					</uni-forms-item>
					<uni-forms-item label="甲烷(%)：" required name="methane">
						<uni-easyinput v-model="anaValiFormData.methane" placeholder="请输入" :inputBorder="false" />
					</uni-forms-item>
					<uni-forms-item label="甲烷(LEL)：" required name="methaneLel">
						<uni-easyinput v-model="anaValiFormData.methaneLel" placeholder="请输入" :inputBorder="false" />
					</uni-forms-item>
					<uni-forms-item label="硫化氢：" required name="h2s">
						<uni-easyinput v-model="anaValiFormData.h2s" placeholder="请输入" :inputBorder="false" />
					</uni-forms-item>
					<uni-forms-item label="一氧化碳：" required name="co">
						<uni-data-select :localdata="peopleOption" v-model="anaValiFormData.co" />
					</uni-forms-item>
					<uni-forms-item label="取样分析时间：" required name="analysisTime">
						<uni-datetime-picker :border="false" type="date" v-model="anaValiFormData.analysisTime" />
					</uni-forms-item>

					<uni-forms-item label="分析部位：" required name="analysisSite">
						<uni-datetime-picker :border="false" type="date" v-model="anaValiFormData.analysisSite" />
					</uni-forms-item>
					<uni-forms-item label="分析人：" required name="analyst">
						<uni-datetime-picker :border="false" type="date" v-model="anaValiFormData.analyst" />
					</uni-forms-item>
					<uni-forms-item label="实施时间：" required name="implementTime">
						<uni-datetime-picker :border="false" type="date" v-model="anaValiFormData.implementTime" />
					</uni-forms-item>
				</uni-forms>
				<view class="btns">
					<button class="submit-btn">结束作业</button>
					<button class="submit-btn">新增作业分析</button>
				</view>
				<view class="title"> 指定签字人 </view>
				<uni-forms ref="anaValiForm" :rules="anaRules" :modelValue="anaValiFormData" border>
					<uni-forms-item label="结束作业负责人：" required name="analyzePeople">
						<uni-data-select :localdata="peopleOption" v-model="valiFormData.analyzePeople" />
					</uni-forms-item>
				</uni-forms>

			</tempalte>
			<template v-else-if="topProcessTitle[5] == '指定签字人'">
				<view class="title"> 指定签字人 </view>
				<uni-forms ref="anaValiForm" :rules="anaRules" :modelValue="anaValiFormData" border>
					<uni-forms-item label="结束作业负责人：" required name="overApprover">
						<uni-data-select :localdata="allUsers" v-model="anaValiFormData.overApprover"
							:arrayConfig="configParams" />
					</uni-forms-item>
				</uni-forms>
			</template>
			<button class="submit-btn" @click="onSubmit(6, topProcessTitle[5])">确认</button>
		</view>

		<!-- 结束作业 -->
		<view class="flow-measure" v-if="flowNum === 7">
			<view class="title"> 确认人签字 </view>
			<view class="charge-people">



				<text>安全措施到位，作业票检验确认无误</text>
				<view class="sign" v-if="finishObj.url == ''" @click="handleSign(7)"> 请在这个区域进行签字 </view>
				<view v-if="finishObj.url">
					<image :src="finishObj.url"></image>
				</view>
			</view>

			<!-- <view class="img-upload">
				<view class="title">上传图片：</view>
				<uni-file-picker v-model="imageValue" fileMediatype="image" mode="grid" @select="select"
					@progress="progress" @success="success" @fail="fail" />
			</view> -->

			<button class="submit-btn" @click="onSubmit(7)">确认</button>
		</view>

		<!-- 签字弹窗 -->
		<uni-popup ref="popup" type="center" width="100%" background-color="#fff" height="600px">
			<uni-nav-bar back-text="返回" :custom-back="backTwo" title="签字"></uni-nav-bar>

			<view style="width: 750rpx ;height: 500rpx;">
				<jp-signature ref="signatureRef"></jp-signature>
			</view>
			<view>
				<button @click="clear">清空</button>
				<button @click="undo">撤消</button>
				<button @click="save">保存</button>
			</view>
			</u-form>
		</uni-popup>
	</view>
</template>
<script>
	import {
		formatType,
		jobProcessTitle,
		noAnalysisTitle,
		workTypeFlowBtn,
		haveAnalysisTitle,
		foramtConfirmItem,
	} from "utils/tool.js"
	import {
		operateFireWork
	} from "@/api/specialWork/hotWork.js"
	import widowHeightMixins from "@/mixins/widowHeightMixins.js";


	import {
		mapState,
		mapGetters
	} from "vuex";
	export default {
		mixins: [widowHeightMixins],
		onLoad(e) {
			let eventChannel = this.getOpenerEventChannel()
			eventChannel.on('customEvent', (data) => {

				this.detailObj = data.specialVo

			})
			// console.log(e, "e");
			this.flowNum = +e.flow;
			this.specialJobType = e.title
			this.nowId = e.id
			// const workTypeText = this.getFlowName(e.flow);
			this.workTypeText = workTypeFlowBtn(e.flow, e.title)
			// 动态设置标题
			uni.setNavigationBarTitle({
				title: `${e.title}---${this.workTypeText}`,
			});
		},
		data() {
			return {
				flowNum: null,
				signShow: false,

				workTypeText: "", //流程步骤
				specialJobType: "", //特殊作业类型
				checkbox1: [0],
				noticeCheck: [{
					text: '我已明白本作业许可证规定内容，并告知每一个相关人员，共同遵守执行；相关安全措施已全部落实，符合作业要求。',
					value: 0
				}, ],
				//人员的格式化
				configParams: {
					valueKey: "userId",
					labelKey: "nickName"
				},
				//特殊作业详情的对象
				detailObj: {},
				//当前特殊作业ID
				nowId: "",
				//措施填写对象
				measureFill: {
					url: "",
					fileInfoList: []
				},
				//措施确认对象
				measureConfirm: {
					url: "",
					fileInfoList: []
				},
				//现场确认对象
				siteConfirm: {
					url: "",
					fileInfoList: []
				},
				//审核
				examineObj: {
					approvalStatus: null,
					url: "",
					fileInfoList: []
				},
				// 作业分析
				anaValiFormData: {
					dynamicItem: [{}]
				},
				finishObj: {
					url: "",
					fileInfoList: []
				},
				//查看审核对象
				viewExamineObj: {},
				//审批步骤文字
				signTitle: "",
				workStatus: false, //作业状态
				tableData: [],
				// 校验表单数据
				valiFormData: {
					chargePeople: "", //动火负责人
					tutelagePeople: "", //动火监护人
					operationPeople: "", //动火操作证
				},
				// 动火人下拉框
				peopleOption: [{
						value: 0,
						text: "人员1"
					},
					{
						value: 1,
						text: "人员2"
					},
					{
						value: 2,
						text: "人员3"
					},
				],
				rules: {},
				imageValue: [],
				approve: "", //审批意见
				approveArr: [{
						text: "通过",
						value: 1,
					},
					{
						text: "驳回",
						value: 2,
					},
				],

				anaRules: {},
			};
		},
		methods: {
			submit(aa, index) {
				this.tableData[index].aa = "fd(22)";
				console.log(aa, "真的触发了");
			},
			/** 结束作业按钮 */
			finishBtn() {

				this.workStatus = true; //结束作业
			},
			//新增方法
			addItem() {
				this.anaValiFormData.dynamicItem.push({
					regionSign: [],
					// name: "",
					// phone: "",
					// address: "",
				});
			},
			//删除方法
			deleteItem(item, index) {
				this.anaValiFormData.dynamicItem.splice(index, 1);
			},
			//提交的
			async onSubmit(val, title) {
				if (val == 2) { //措施填写
					this.measureFill.contentFilling = JSON.stringify(this.confirmItem)
					this.measureFill.id = this.nowId
					this.measureFill.specialJobType = this.specialJobType

					if (this.measureFill.fileInfoList.length <= 0) {
						uni.showToast({
							icon: 'error',
							duration: 3000,
							title: `请签字后确认`
						});
					} else {
						delete this.measureFill.url
						await operateFireWork(this.measureFill)

						uni.showToast({
							title: `新增成功`,
						});
						uni.navigateTo({
							url: "/pages/specialWork/index",
						})

					}

				} else if (val == 3) { //措施确认
					this.measureConfirm.contentFilling = JSON.stringify(this.confirmItem)
					this.measureConfirm.id = this.nowId
					this.measureConfirm.specialJobType = this.specialJobType

					if (this.measureConfirm.fileInfoList.length <= 0) {
						uni.showToast({
							icon: 'error',
							duration: 3000,
							title: `请签字后确认`
						});
					} else {
						delete this.measureConfirm.url
						await operateFireWork(this.measureConfirm)

						uni.showToast({
							title: `新增成功`,
						});
						uni.navigateTo({
							url: "/pages/specialWork/index",
						})

					}
				} else if (val == 4) { //现场确认

					if (this.siteConfirm.fileInfoList.length <= 0) {
						uni.showToast({
							icon: 'error',
							duration: 3000,
							title: `请签字后确认`
						});
					} else {
						this.siteConfirm.id = this.nowId
						this.siteConfirm.specialJobType = this.specialJobType
						delete this.siteConfirm.url
						await operateFireWork(this.siteConfirm)

						uni.showToast({
							title: `新增成功`,
						});
						uni.navigateTo({
							url: "/pages/specialWork/index",
						})

					}
				} else if (val == 5) { //审核
					if (this.examineObj.fileInfoList.length <= 0) {
						uni.showToast({
							icon: 'error',
							duration: 3000,
							title: `请签字后确认`
						});
					} else {
						this.examineObj.id = this.nowId
						this.examineObj.specialJobType = this.specialJobType

						delete this.examineObj.url
						await operateFireWork(this.examineObj)

						uni.showToast({
							title: `新增成功`,
						});
						uni.navigateTo({
							url: "/pages/specialWork/index",
						})

					}
				} else if (val == 6) { //作业分析
					if (title == "指定签字人") {
						this.anaValiFormData.id = this.nowId
						this.anaValiFormData.specialJobType = this.specialJobType

						delete this.anaValiFormData.dynamicItem
						let query = {
							id: this.nowId,
							specialJobType: this.specialJobType,
							overApprover: this.anaValiFormData.overApprover,
						};

						await operateFireWork(query)
					} else {
						this.anaValiFormData.id = this.nowId
						this.anaValiFormData.specialJobType = this.specialJobType
						this.anaValiFormData.jobAnalysis = JSON.stringify(this.anaValiFormData.dynamicItem)
						delete this.anaValiFormData.dynamicItem
						await operateFireWork(this.anaValiFormData)
					}


					uni.showToast({
						title: `编辑成功`,
						duration: 2000
					});
					uni.navigateTo({
						url: "/pages/specialWork/index",
					})


				} else if (val == 7) { //结束作业
					if (this.finishObj.fileInfoList.length <= 0) {
						uni.showToast({
							icon: 'error',
							duration: 3000,
							title: `请签字后确认`
						});
					} else {
						this.finishObj.id = this.nowId
						this.finishObj.specialJobType = this.specialJobType

						delete this.finishObj.url
						await operateFireWork(this.finishObj)

						uni.showToast({
							title: `确认成功`,
						});
						uni.navigateTo({
							url: "/pages/specialWork/index",
						})

					}
				}

			},
			getFlowName(flowActive) {
				const flowNameMap = {
					0: "作业申请",
					1: "措施确认",
					2: "现场确认",
					3: "审核",
					4: "作业分析",
					5: "结束作业",
				};

				const result = flowNameMap[flowActive] || flowActive;
				return result;
			},
			//保存
			save() {
				let config = require('@/config.js')
				// 是否为空画板 无签名

				this.$refs.signatureRef.canvasToTempFilePath({
					success: (res) => {
						// 生成图片的临时路径
						// H5 生成的是base64
						if (res.isEmpty == false) {
							// this.url = res.tempFilePath
							let blob = this.dataURLtoBlob(res.tempFilePath);
							// 拿到文件名
							let fileName = "电子签名.jpg";
							// 2，在转为 file类型
							let file = this.blobToFile(blob, fileName);
							const formData = new FormData();
							formData.append("file", file);

							uni.uploadFile({
								url: `${config.baseUrl}/common/upload`,
								header: {
									'Authorization': 'Bearer ' + uni.getStorageSync(
										'App-Token') //请求头信息
								},
								filePath: res.tempFilePath,
								name: 'file',
								success: (res) => {
									let response = JSON.parse(res.data)
									// @params  status: 状态判断上传文件穿什么type
									let result = formatType(this.specialJobType, this.workTypeText,
										response, this.detailObj.yesStatus, this.signTitle)
									if (this.workTypeText == '措施填写') {
										this.measureFill.fileInfoList.push(result)
										this.measureFill.url = result.url
									} else if (this.workTypeText == '措施确认') {
										this.measureConfirm.fileInfoList.push(result)
										this.measureConfirm.url = result.url
									} else if (this.workTypeText == '现场确认') {
										this.siteConfirm.fileInfoList.push(result)
										this.siteConfirm.url = result.url
									} else if (this.workTypeText == '审核') {
										this.examineObj.fileInfoList.push(result)
										this.examineObj.url = result.url

										uni.showToast({
											title: `填写成功`,
										});
									} else if (this.workTypeText == '结束作业') {
										this.finishObj.fileInfoList.push(result)
										this.finishObj.url = result.url
										uni.showToast({
											title: `确认成功`,
										});
									}



									this.$refs.popup.close()

								}
							})
						}
					}
				})
			},

			//1,先将base64转换为blob
			dataURLtoBlob(baseurl) {
				var arr = baseurl.split(","),
					mime = arr[0].match(/:(.*?);/)[1],
					bstr = atob(arr[1]),
					n = bstr.length,
					u8arr = new Uint8Array(n);
				while (n--) {
					u8arr[n] = bstr.charCodeAt(n);
				}
				return new Blob([u8arr], {
					type: mime
				});
			},
			//2,再将blob转换为file
			blobToFile(theBlob, fileName) {
				theBlob.lastModifiedDate = new Date(); // 文件最后的修改日期
				theBlob.name = fileName; // 文件名
				return new File([theBlob], fileName, {
					type: theBlob.type,
					lastModified: Date.now(),
				});
			},
			//清除
			clear() {
				this.$refs.signatureRef.clear()
			},
			//撤销按钮
			undo() {
				this.$refs.signatureRef.undo()
			},
			//签字的按钮
			handleSign(val) {

				this.signTitle = val
				this.$refs.popup.open('center')
			},
			backTwo() {
				this.signShow = false
			},
			// 获取上传状态
			select(e) {
				console.log("选择文件：", e);
			},
			handleFile(e) {
				console.log("自定义选择文件：", e);
				let file = e.tempFiles[0]

				this.siteConfirm.fileInfoList.push({
					fileId: file.uuid,
					fileName: file.name,
					type: 36,
					url: file.url
				})
				console.log("文件数组", this.imageValue)
			},
			//去重
			removeObjectById(arr, id) {
				let index = arr.findIndex(obj => obj.fileId === id);
				if (index !== -1) {
					arr.splice(index, 1);
				}
				return arr;
			},

			//删除文件
			deleteFile(e) {
				// console.log("删除文件", e)
				let file = e.tempFile
				let arr = this.removeObjectById(this.siteConfirm.fileInfoList, file.uuid)
			},
			// 获取上传进度
			progress(e) {
				console.log("上传进度：", e);
			},

			// 上传成功
			success(e) {
				console.log("上传成功");
			},

			// 上传失败
			fail(e) {
				console.log("上传失败：", e);
			},
		},
		computed: {
			//措施确认项
			confirmItem() {
				return foramtConfirmItem(this.specialJobType)
			},
			//措施确认签字人标题
			cobfirmSignTitle() {
				if (this.specialJobType == "动火作业票") {
					return "动火监护人签字";
				} else {
					return "确认人签字";
				}
			},

			//《审核》流程签字人文字
			examineProcessTitle() {
				return jobProcessTitle(this.specialJobType, this.detailObj.specialGrade)
			},
			//作业分析上面的文字
			topProcessTitle() {
				if (this.specialJobType == "动火作业票" || this.specialJobType == "受限空间安全作业票") {
					return haveAnalysisTitle();
				} else {
					return noAnalysisTitle();
				}
			},

			...mapGetters(["allUsers"]),

		},
		mounted() {

		}
	};
</script>

<style lang="scss" scoped>
	.flow-container {
		background-color: #fff;
		overflow-y: auto;

		.flow-measure {
			padding: 20rpx;

			.top-title {
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.title {
				margin: 20rpx 0;
				height: 60rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 600;
				font-size: 32rpx;
				color: #515a6e;
				text-align: left;
				font-style: normal;
			}

			.table {
				height: 90%;
				background: #ffffff;
				border-radius: 16rpx;

				::v-deep {
					.click-table {
						background: #ffffff;
						border-radius: 16rpx;
						border: 2rpx solid #dcdee2;

						// 表头
						.uni-table-th {
							background: #f8fcff;

							.uni-table-th-content {
								font-family: PingFangSC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #17233d;
								line-height: 34rpx;
								text-align: left;
								font-style: normal;
							}
						}
					}

					// 表主体内容
					.uni-table-tr {
						.uni-table-td {
							padding: 30rpx 0; //取消原来设置的padding
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #808695;
							line-height: 34rpx;
							text-align: left;
							font-style: normal;
						}
					}
				}
			}

			// 动火负责人签字
			.charge-people {
				position: relative;
				padding: 20rpx;
				background: #ffffff;
				border-radius: 20rpx;
				border: 2rpx solid #dcdee2;

				.check-box {
					margin-right: 20rpx;
				}

				.view-img {
					border: 1px dashed #e4dbdb;
					margin-bottom: 5px;
				}

				.sign {
					margin-top: 20rpx;
					height: 240rpx;
					background: #ffffff;
					border-radius: 10rpx;
					border: 2rpx dashed #dcdee2;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 32rpx;
					color: #c5c8ce;
					line-height: 200rpx;
					text-align: center;
					font-style: normal;


				}

				.time {
					position: absolute;
					bottom: 20rpx;
					right: 5%;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #808695;
					font-style: normal;
				}
			}

			::v-deep {
				.uni-forms-item--border {
					border-top: 0 solid #000;
					border-bottom: 2rpx solid #e8eaec;
				}

				.uni-forms-item__label {
					width: 40% !important;
				}

				.submit-btn {
					margin-top: 30rpx;
					background: #137ee9;
					border-radius: 10rpx;
					color: #fff;
				}
			}

			.img-upload {
				padding-bottom: 20rpx;
				margin: 20rpx 0;
				border-bottom: 1px solid #e8eaec;
				display: flex;

				.title {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #17233d;
					line-height: 3rpx;
					text-align: left;
					font-style: normal;
				}
			}

			.btns {
				display: flex;
			}
		}
	}
</style>